package db

import (
	// "fmt"

	"doubimeizhi.com/utility"

	"github.com/astaxie/beego"
)

var (
	hpimysqlHelper *utility.MySQLHelper
)

func createHomePageInfoMySQLHelper() bool {
	mysqlHost := beego.AppConfig.DefaultString("mysql_homepage::host", "127.0.0.1")
	mysqlPort := beego.AppConfig.DefaultInt("mysql_homepage::port", 4100)
	mysqlUser := beego.AppConfig.DefaultString("mysql_homepage::user", "devuser")
	mysqlPass := beego.AppConfig.DefaultString("mysql_homepage::password", "devpass")
	mysqlDB := beego.AppConfig.DefaultString("mysql_homepage::db", "homepage_info")
	maxOpenConns := beego.AppConfig.DefaultInt("mysql_homepage::maxOpenConns", 10)
	maxIdleConns := beego.AppConfig.DefaultInt("mysql_homepage::maxIdleConns", 5)
	hpimysqlHelper = utility.NewMySQLHelper(mysqlHost, mysqlPort, mysqlUser, mysqlPass, mysqlDB, maxOpenConns, maxIdleConns)
	return true
}

/*
	获取Mysql操作的句柄
*/
func GetHomePageInfoMysqlHelper() *utility.MySQLHelper {
	if hpimysqlHelper == nil {
		createHomePageInfoMySQLHelper()
	}
	return hpimysqlHelper
}
